#include "linkedlist.h"
#include <stdlib.h>

void dotlist_init(Dot** head) {
    *head = NULL;
}

void dotlist_insert(Dot** head, int row, int col) {
    Dot* newDot = (Dot*)malloc(sizeof(Dot));
    if (!newDot) return;
    newDot->row = row;
    newDot->col = col;
    newDot->next = *head;
    *head = newDot;
}

int dotlist_remove(Dot** head, int row, int col) {
    Dot* current = *head;
    Dot* previous = NULL;
    while (current) {
        if (current->row == row && current->col == col) {
            if (previous) previous->next = current->next;
            else *head = current->next;
            free(current);
            return 1;
        }
        previous = current;
        current = current->next;
    }
    return 0;
}

void dotlist_free(Dot** head) {
    Dot* current = *head;
    while (current) {
        Dot* next = current->next;
        free(current);
        current = next;
    }
    *head = NULL;
}

int dotlist_count(Dot* head) {
    int count = 0;
    Dot* current = head;
    while (current) {
        count++;
        current = current->next;
    }
    return count;
}

Dot* dotlist_find(Dot* head, int row, int col) {
    Dot* current = head;
    while (current) {
        if (current->row == row && current->col == col) return current;
        current = current->next;
    }
    return NULL;
} 